home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-02-12 | 2.8 KB | 100 lines | [TEXT/Mrls] |
- module: dylan-user
- description: example of using window graphics and menus.
-
- // need a require form to prevent multiple loads.
- load("Windows.dyl");
- load("Menus.dyl");
-
- /*
- define module Window-Menu
- use dylan-user, export: all;
- use Windows, export: all;
- use Menus, export: all;
- end module Window-Menu;
- */
-
- define constant line-window-updater = method (window :: <window>)
- let bounds = window.bounds;
- let width = bounds[3] - bounds[1]; // right - left;
- let half-width = truncate/ (width, 2);
- let height = bounds[2] - bounds[0]; // bottom - top;
- let half-height = truncate/ (height, 2);
- window-erase(window);
- window-draw-line(window, vector(0, 0, height, width));
- window-draw-line(window, vector(height, 0, 0, width));
- window-draw-line(window, vector(half-height, 0, half-height, width));
- window-draw-line(window, vector(0, half-width, height, half-width));
- window-move-to(window, 0, half-height);
- window-draw-string(window, "Text!");
- end method;
-
- define constant make-line-window = method ()
- // create a new window. windows are initially invisible by default.
- let window = make(<window>,
- title: "Graphics",
- bounds: #[50, 10, 250, 310],
- updater: line-window-updater);
- // set up some attributes. a 3x3 pen.
- window.pen-size := #[3, 3];
- // use Geneva-24, bold, extend, italic.
- window.text-style := make(<text-style>, font: "Geneva",
- size: 24, face: $bold + $extend + $italic);
- // make the window visible.
- window.visible := #t;
- window;
- end method;
-
- // create a menu that controls windows.
-
- define constant window-menu-behavior = method (menu :: <menu>, item :: <string>)
- if (item = "Create")
- make-line-window();
- else
- let window = front-window();
- if (window)
- if (item = "Destroy")
- window-dispose(window);
- else
- window.visible := (item = "Show");
- end if;
- end if;
- end if;
- end method;
-
- define constant window-menu-adjuster = method (menu :: <menu>)
- let items = #("Destroy", "Show", "Hide");
- let state = (front-window() ~= #f);
- menu-set-item-states(menu, items, list(state, state, state));
- end method;
-
- define constant make-window-menu = method ()
- let menu = make(<menu>, title: "Window", id: 1000,
- items: #("Create", "Destroy", "-", "Show", "Hide"),
- behavior: window-menu-behavior,
- adjuster: window-menu-adjuster);
- menu-enable-item(menu, "Create");
- window-menu-adjuster (menu);
- menu-insert(menu);
- menu-draw();
- menu;
- end method;
-
- define variable *window-menu* = make-window-menu ();
-
- /*
- {an anonymous method ()
- ("unbinding-begin 1
- ("local-bind
- ((menu (make <menu>
- #"title" "Window"
- #"id" 1000
- #"items" (quote ("Create" "Destroy" "-" "Show" "Hide"))
- #"behavior" window-menu-behavior
- #"adjuster" window-menu-adjuster))))
- (menu-enable-item menu "Create")
- (window-menu-adjuster menu)
- (menu-insert menu)
- (menu-draw)
- menu)}
- */
-